/*
 * SendMediaPort.h
 *
 *  Created on: 2017年4月14日
 *      Author: chuanjiang.zh
 */

#ifndef SENDMEDIAPORT_H_
#define SENDMEDIAPORT_H_

#include "MediaPort.h"
#include "TCriticalSection.h"
#include "RtpMedium.h"
#include "Sdp.h"
#include "CRtpSink.h"
#include "PcmFileSource.h"


class SendMediaPort : public MediaPort, public PcmFileSourceSink
{
public:
	SendMediaPort();
	virtual ~SendMediaPort();

	virtual void setOriginSdp(const std::string& sdp);

	virtual std::string getLocalSdp();

	virtual int setPeerSdp(std::string& peerSdp);

	virtual std::string getPeerSdp(std::string& offerSdp);

	virtual int start();

	virtual void stop();

	void setPath(const std::string& pcmfile);

	void handlePacket(StreamPacket* pPacket);

	void setPacketSize(int size);

protected:
	virtual void onPcmData(uint8_t* data, size_t size, int64_t pts);

protected:
	std::string apply(const std::string& localSdp, const std::string& peerSdp);

	int setup(const std::string& localSdp, const std::string& peerSdp);

	bool setupMedium(sdp::SessionDescription& local, sdp::SessionDescription& peer,
		const char* name, RtpMedium& rtpMedium, int& localPort);

protected:
	std::string m_originSdp;

	std::string m_localSdp;
	std::string m_peerSdp;
	bool    m_connected;

	std::string m_pcmFile;

	RtpMedium m_medium;

	bool m_running;

	int	m_localPort;

	comn::CriticalSection	m_cs;
	CRtpSink	m_rtpCaster;
	PcmFileSource	m_pcmSource;

};


#endif /* SENDMEDIAPORT_H_ */
